/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

#include <gtest/gtest.h>
#include <cstdio>
#include <hal_mtd.h>

class TestRAM : public ::testing::Test
{
protected:
    void SetUp()
    {
        mtd = hal_mtd_open("ram");
        if (mtd == NULL) {
            GTEST_SKIP() << "RAM MTD not available";
        }
    };

    void TearDown() {};
public:
    hal_mtd_t *mtd;
};

TEST_F(TestRAM, write)
{
    uint8_t buf[16] = {0};
    uint32_t len = 16;
    uint32_t pos = 0;
    for (uint32_t i = 0; i < len; i++) {
        buf[i] = i;
    }
    EXPECT_EQ(0, hal_mtd_write(mtd, pos, len, buf));
    memset(buf, 0, sizeof(buf));
    EXPECT_EQ(0, hal_mtd_read(mtd, pos, len, buf));
    for (uint32_t i = 0; i < len; i++) {
        EXPECT_EQ(buf[i], i);
    }
}
